package edu.gxmzu.task.controller;

import edu.gxmzu.task.service.UserService;
import edu.gxmzu.task.utils.RedisService;
import edu.gxmzu.task.utils.Result;
import edu.gxmzu.task.entity.UserBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "用户模块")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/users")
    @Operation(summary = "用户删除（批量）")
    public Result<String> deleteUser(@RequestBody UserBody userBody) {

        if (userBody.getUserIds() == null || userBody.getUserIds().isEmpty()) {
            return Result.fail("用户id不能为空");
        }

        int result = userService.deleteUser(userBody.getUserIds());
//        redisService.deleteValue(RedisService.USER_KEY + username);
        if (result > 0) {
            return Result.ok("用户删除成功");
        } else {
            return Result.fail("用户删除失败");
        }
    }
}
